﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ADC.DAL;
namespace ADC.BL
{
    public class SlideFactory
    {
        public static List<Slide> GetAll()
        {
            var db = new dbADCEntities ();
            return db.Slides.ToList();
        }

        public static Slide SelectByID(int slideID)
        {
            var db = new dbADCEntities();
            return db.Slides.Where(g => g.SlideID == slideID).FirstOrDefault();
        }

        public static int Update(Slide slide)
        {
            var db = new dbADCEntities();
            var objSlide = new Slide();
            objSlide = db.Slides.Where(g => g.SlideID == slide.SlideID).FirstOrDefault();
            objSlide.Title = slide.Title;
            objSlide.Link = slide.Link;
            if (slide.ImagePath != "")
            {
                objSlide.ImagePath = slide.ImagePath;
            }
            return db.SaveChanges();
        }

        public static int Insert(Slide slide)
        {
            var db = new dbADCEntities();
            db.AddToSlides(slide);
            return db.SaveChanges();
        }

        public static int Delete(int slideID)
        {

            var db = new dbADCEntities();
            var slide = db.Slides.Where(g => g.SlideID == slideID).FirstOrDefault();
            db.DeleteObject(slide);
            return db.SaveChanges();
        }
    }
}
